﻿using System;
using System.IO;
using System.Threading;
using System.Reflection;
using System.Collections.Generic;

namespace BbsbWebService.Logging
{
    public class Logger : ILogger
    {
        private static Logger _instance;
        public static Logger Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new Logger();
                }

                return _instance;
            }
        }
        private List<ILogger> loggers = new List<ILogger>();

        public void RegisterLogger(ILogger logger)
        {
            if (!loggers.Contains(logger))
            {
                loggers.Add(logger);
            }
        }

        public void UnregisterLogger(ILogger logger)
        {
            if (loggers.Contains(logger))
            {
                loggers.Remove(logger);
            }
        }

        #region ILogger Members

        public void LogMessage(string message, params object[] stringFormatArgs)
        {
            foreach (var logger in loggers)
                logger.LogMessage(message, stringFormatArgs);
        }

        public void LogException(Exception ex, string message, params object[] stringFormatArgs)
        {
            foreach (var logger in loggers)
                logger.LogException(ex, message, stringFormatArgs);
        }

        public void LogListener(string message, params object[] stringFormatArgs)
        {
            foreach (var logger in loggers)
                logger.LogListener(message, stringFormatArgs);
        }

        #endregion
    }
}
